package com.buaa.wangrui.client.panel;

import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;

public class LoadingPanel extends SimplePanel{
	
      private int loadCount = 0;
      
      public LoadingPanel(){
    	  
    	  setStyleName("gwtapps-LoadingPanel");
    	  setVisible(false);
      }
      public  LoadingPanel(Widget child){
    	  
    	  this();
    	  setWidget(child);
      }
      public void LoadingBegin(){
    	  
    	  if(loadCount==0){
    		  setVisible(true);
    		  DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "progress");
    		  setPosition();
    	  }
    	  loadCount++;
      }
      public void LoadingEnd(){
    	  loadCount--;
    	  if(loadCount==0){
    		  
    		  setVisible(false);
    		  DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "");
    	  }
    	  
      }
	private void setPosition() {
		// TODO Auto-generated method stub
		Widget child = getWidget();
		int top = DOM.getIntAttribute(RootPanel.getBodyElement(), "scrollTop");
		int left = Window.getClientWidth()-child.getOffsetWidth()+DOM.getIntAttribute(RootPanel.getBodyElement(), "scroolLeft");
		
		DOM.setStyleAttribute(RootPanel.getBodyElement(), "positon", "absolute");
		DOM.setStyleAttribute(RootPanel.getBodyElement(), "top", Integer.toString(top));
		DOM.setStyleAttribute(RootPanel.getBodyElement(), "left", Integer.toString(left));
	}
      
}
